<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Msgpage extends CI_Controller {
	
	var $sidebardata = array('page'=>'msgpage');

	public function index()
	{
		$this->page->showSide($this->sidebardata,'content/msg/main');
	}
	
	public function all()
	{
		if (@isset($_POST['delete']))
		{
			if (isset($_POST['itemno']))
			{
				$items = $_POST['itemno'];
				foreach($items as $msgid)
				{
					$this->message->delete($msgid);
				}
			}
			else
			{
				$this->sidebardata['WarningMsg'] = "请选择要删除的消息！";
			}
		}
		$userid = $this->loginc->getUserId();
		$this->sidebardata['msgs'] = $this->message->getAllArray($userid);
		$this->page->showSide($this->sidebardata,'content/msg/all');
	}
	
	public function unread()
	{
		if (@isset($_POST['delete']))
		{
			if (isset($_POST['itemno']))
			{
				$items = $_POST['itemno'];
				foreach($items as $msgid)
				{
					$this->message->delete($msgid);
				}
			}
			else
			{
				$this->sidebardata['WarningMsg'] = "请选择要删除的消息！";
			}
		}
		if (@isset($_POST['mark']))
		{
			if (isset($_POST['itemno']))
			{
				$items = $_POST['itemno'];
				foreach($items as $msgid)
				{
					$this->message->markAsRead($msgid);
				}
			}
			else
			{
				$this->sidebardata['WarningMsg'] = "请选择要标记为已读的消息！";
			}
		}
		$userid = $this->loginc->getUserId();
		$this->sidebardata['msgs'] = $this->message->getUnreadArray($userid);
		$this->page->showSide($this->sidebardata,'content/msg/unread');
	}
	
	public function write()
	{
		if (@isset($_POST['send']))
		{
			$to = $_POST['msg_to'];
			$from = $this->loginc->getUserId();
			$content = $_POST['content'];
			if (!$this->message->send($content,$to,$from))
			{
				$this->sidebardata['FailMsg'] = "发送失败，可能接收方用户ID不存在";
			}
			else
			{
				$this->sidebardata['SuccessMsg'] = "发送成功";
			}
		}
		$this->page->showSide($this->sidebardata,'content/msg/write');
	}
	
}

/* End of file user.php */
/* Location: ./application/controllers/user.php */